# -*- coding: utf-8 -*-
# @Author  : lang

import xlrd


class ExcelUtil():

    def __init__(self,path) -> None:
        self.data = xlrd.open_workbook(path)
        self.sheet = self.data.sheet_by_name("Sheet1")
        self.keys = self.sheet.row_values(0)
        self.row_num = self.sheet.nrows


    def dict_data(self):
        result = list()
        for r in range(1, self.row_num):
            data_list = self.sheet.row_values(r)
            data_zip = zip(self.keys, data_list)
            item = {}
            for k, v in data_zip:
                item[k] = v
            result.append(item)

        return result


if __name__ == "__main__":
    filepath = "D:\\1.xlsx"
    data = ExcelUtil(filepath).dict_data()
    # print(data)
    print(data[0].get("group_code"))
    print(data[0].get("group_name"))

    print(data[1].get("group_code"))
    print(data[1].get("group_name"))